package com.battle.service.controller.web;

import com.battle.pojo.param.organization.*;
import com.battle.pojo.vo.organization.*;
import com.battle.service.service.in.*;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * web/组织架构
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@RestController
@RequestMapping("/organization/web")
public class OrganizationWebController {

    private final OrganizationService service;

    public OrganizationWebController(OrganizationService service) {
        this.service = service;
    }


    /**
     * 创建组织架构
     *
     * @param param
     * @return
     */
    @PostMapping("/createOrganization")
    public ApiResult createOrganization(@RequestBody @Valid CreateOrganizationParam param) {
        service.createOrganization(param);
        return ApiResult.ok();
    }


    /**
     * 修改组织架构
     *
     * @param param
     */
    @PutMapping("/editOrganization")
    public ApiResult editOrganization(@RequestBody @Valid EditOrganizationParam param) {
        service.editOrganization(param);
        return ApiResult.ok();
    }

    /**
     * 移除组织架构
     *
     * @param id
     */
    @DeleteMapping("/removeOrganization")
    public ApiResult removeOrganization(@RequestParam("id") Long id) {
        service.removeOrganization(id);
        return ApiResult.ok();
    }

    /**
     * 启动/禁用组织架构
     *
     * @param id
     */
    @GetMapping("/enabledOrganization")
    public ApiResult enabledOrganization(@RequestParam("id") Long id) {
        service.enabledOrganization(id);
        return ApiResult.ok();
    }

    /**
     * 获取组织架构详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getOrganization")
    public ApiResult<GetOrganizationVo> getOrganization(@RequestParam("id") Long id) {
        GetOrganizationVo vo = service.getOrganization(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取组织架构列表
     *
     * @param param
     * @return
     */
    @PostMapping("/getOrganizationList")
    public ApiResult<PageResult<GetOrganizationListVo>> getOrganizationList(@RequestBody GetOrganizationListParam param) {
        PageResult<GetOrganizationListVo> result = service.getOrganizationList(param);
        return ApiResult.ok(result);
    }


    /**
     * 获取组织架构树形
     *
     * @return
     */
    @PostMapping("/getOrganizationTreeList")
    public ApiResult<List<GetOrganizationTreeListVo>> getOrganizationTreeList() {
        List<GetOrganizationTreeListVo> list = service.getOrganizationTreeList();
        return ApiResult.ok(list);
    }

    /**
     * 获取组织架构下拉列表
     *
     * @return
     */
    @PostMapping("/getOrganizationDownList")
    public ApiResult<List<GetOrganizationDownListVo>> getOrganizationDownList(@RequestBody(required = false) @Valid GetOrganizationDownListParam param) {
        List<GetOrganizationDownListVo> list = service.getOrganizationDownList(param);
        return ApiResult.ok(list);
    }

    /**
     * 导入组织架构
     *
     * @param file
     * @return
     */
    @PostMapping("/importOrganization")
    public void importOrganization(@RequestParam("file") MultipartFile file) {
        service.importOrganization(file);
    }

}

